{php include $this->template('_header');}
{if $op=='display'}
<script type="text/javascript" src="{MODULE_URL}template/mobile/ZeroClipboard/ZeroClipboard.js"></script>
<div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 视频管理</strong></div>
    <div class="padding border-bottom">
        <form action="./index.php" method="get">
			<input type="hidden" name="i" value="{$uniacid}">
            <input type="hidden" name="c" value="entry">
            <input type="hidden" name="m" value="fy_teacher">
            <input type="hidden" name="do" value="tencent">
            <input type="hidden" name="op" value="display">
            <ul class="search" style="padding-left:10px;">
                <li> <a class="button border-green icon-plus-square-o" href="{php echo $this->createMobileUrl('tencent', array('op'=>'upload'));}"> 上传视频</a> </li>
				<li>
                    <input type="text" placeholder="文件前缀" name="keyword" class="input" style="width:200px; line-height:17px; display:inline-block; margin-left:20px;" value="{$_GPC['keyword']}">
                </li>
				<button type="submit" class="button border-main icon-search"> 搜 索 </button>
            </ul>
        </form>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th style="width:15%;">预览(点击画面播放)</th>
            <th style="width:20%;">文件名称</th>       
            <th style="width:10%;">文件大小</th>
            <th style="width:10%;">状态</th>
            <th style="width:15%;">上传时间</th>
            <th style="width:30%;">文件链接</th>       
        </tr>
		{if !empty($list['data']['infos'])}
			{loop $list['data']['infos'] $key $item}
			<tr>
				<td>
					<video src="{$item['play_url']}" id="video{$key}" onclick="videoContro(this, {php echo $item['suffix']=='mp4'?0:1;})" {if $item['suffix']!='mp4'}class="" poster="{MODULE_URL}template/mobile/images/preview.png"{else}poster="{MODULE_URL}template/mobile/images/videoCover.png"{/if} width="200"></video>
				</td>
				<td>{$item['name']}</td>
				<td>{php echo round(($item['filesize']/1024)/1024,2)?round(($item['filesize']/1024)/1024,2):0.01;} MB</td>
				<td>
					{if $item['filelen']==0}
					<span class="label-box label-box-info">上传中/文件损坏</span>
					{else}
					<span class="label-box label-box-success">上传完毕</span>
					{/if}
				</td>         
				<td>{php echo date('Y-m-d H:i', $item['ctime']);}</td>
				<td>
					<textarea class="input" id="content{$key}" style="overflow-y:auto;">{$item['video_url']}</textarea>
					<button id="copyId{$key}" onclick="copy(this.id)" class="copy-button" data-clipboard-target="content{$key}">复制链接</button>
				</td>
			</tr>
			<script type="text/javascript">
			var clip = new ZeroClipboard(document.getElementById("copyId{$key}"), {
				moviePath: "{MODULE_URL}template/mobile/ZeroClipboard/ZeroClipboard.swf"
			});
			clip.on('complete', function(client, args) {
				alert("复制成功");
			});
			</script>
			{/loop}
		{else}
		<tr>
            <td colspan="8">
                文件翻阅完毕，将重复显示
			</td>
        </tr>
		{/if}
        <tr>
            <td colspan="8">
                <div class="pagelist">
					<a class="current">每页显示{$listnum}个文件</a>
					<a href="{php echo $this->createMobileUrl('tencent', array('order'=>0,'context'=>$list['data']['context']));}" class="pager-nav">上一页</a>
					<a href="{php echo $this->createMobileUrl('tencent', array('order'=>1,'context'=>$list['data']['context']));}" class="pager-nav">下一页</a>
				</div>
			</td>
        </tr>
    </table>
</div>
<script type="text/javascript">
document.body.onselectstart=document.body.oncontextmenu=function(){ return false;}
function videoContro(obj, type){
	var myvideo = document.getElementById(obj.id);
	if(document.getElementById(obj.id).paused){
		document.getElementById(obj.id).play();
		if(type==1){
			$("#"+obj.id).addClass('Rotation');
		}
	}else{
		document.getElementById(obj.id).pause();
		$("#"+obj.id).removeClass('Rotation');
	}	
}
</script>
{elseif $op=='upload'}
<link href="{MODULE_URL}template/mobile/QCloud/bootstrap.css" rel="stylesheet">
<script src="{MODULE_URL}template/mobile/QCloud/jquery-1.12.4.min.js"></script>
<script src="{MODULE_URL}template/mobile/QCloud/crypto.js"></script>
<script type="text/javascript" src="{MODULE_URL}template/mobile/QCloud/cos-js-sdk-v4.js"></script>
<style type="text/css">
#overlay {
    background: #000;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    z-index: 100;
    display: none;
}
.mloading-bar {
    width: 300px;
    min-height: 22px;
    text-align: center;
    background: #fff;
    box-shadow: 0px 1px 1px 2px rgba(0, 0, 0, 0.3);
    border-radius: 7px;
    padding: 20px 15px;
    font-size: 14px;
    color: #000;
    position: absolute;
    top: 42%;
    left: 50%;
    margin-left: -140px;
    margin-top: -30px;
    word-break: break-all;
    z-index: 999;
    display: none;
}
.logo{margin-top:-8px;}
.logo img{margin-top:-6px;}
h1{border:none !important; margin-top:24px !important; font-size:24px !important; font-weight:normal !important;}
.table th{text-align:left;}
</style>
<div class="mloading-bar" style="margin-top: -31px; margin-left: -140px;"><img src="{MODULE_URL}template/mobile/images/download.gif"><span id="mloading-text">文件上传中，请勿刷新或关闭浏览器...</span></div>
<div id="overlay" style="height: 100%; width: 100%; opacity: 0.2;"></div>
<div class="panel admin-panel">
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 上传音视频</strong></div>
    <div class="body-content">
		<input type="file" class="input" id="file" accept="audio/mp3,{php echo $video_type?$video_type:'video/mp4';}" style="display:none;">
		<div class="form-group">
			<div class="field">
				<input type="button" class="button bg-main icon-check-square-o" id="sliceUploadFile" value="添加文件">
				<span class="help-block">注意：当前系统上传单个文件限制为{$config['upload_max']}MB，音频请上传mp3格式文件，视频请上传mp4格式文件</span>
			</div>
		</div>
		<div class="row" style="padding:20px;">
			<textarea id="result" class="input" rows="20"></textarea>
		</div>
		<object id="qs" width="0" height="0" type="application/x-shockwave-flash" data="../addons/fy_teacher/template/mobile/QCloud/Somethingtest.swf" style="visibility: visible;"></object>
    </div>
</div>
<script type="text/javascript">
$(function(){
	$("#overlay").height("100%");
	$("#overlay").width("100%");

	var bucket = "{php echo $qcloud['bucket'];}";
	var appid = "{php echo $qcloud['appid'];}";
	var region = "{php echo $qcloud['region'];}";
	var myFolder = "/{php echo $teacher['id'];}/";

	var cos = new CosCloud({
		appid: appid,
		bucket: bucket,
		region: region,
		getAppSign: function (callback) {
			callback("{php echo $signature;}")
		},
		getAppSignOnce: function (callback) {
			callback("")
		}
	});

	var successCallBack = function (result) {
		$(".mloading-bar").hide();
		$("#overlay").hide();

		var res = eval(result);

		var cdnUrl = "{$qcloud['url']}";
		var tmpUrl = res.data.source_url.split("myqcloud.com");
		var resTxt = "============恭喜您，上传成功============";
		resTxt += "\n\n============文件原地址=================\n\n" + res.data.source_url;

		if(cdnUrl!=''){
			resTxt += "\n\n============文件CDN加速地址：==========\n\n" + cdnUrl + tmpUrl[1];
		}

		$("#result").val(resTxt);
	};

	var errorCallBack = function (result) {
		$(".mloading-bar").hide();
		$("#overlay").hide();

		console.log(result);

		var res = eval(result);
		var errorHtml = "";
		if(result.responseJSON.code=='-70'){
			errorHtml = "【请求的appid和签名中的appid不匹配】";
		}else if(result.responseJSON.code=='-71'){
			errorHtml = "【操作太频繁】";
		}else if(result.responseJSON.code=='-96'){
			errorHtml = "【上传失败，原因：签名已过期，请刷新后重试】";
		}else if(result.responseJSON.code=='-97'){
			errorHtml = "【上传失败，原因：签名校验失败】";
		}else if(result.responseJSON.code=='-177'){
			errorHtml = "【上传失败，原因：同名文件已存在】";
		}else if(result.responseJSON.code=='-178'){
			errorHtml = "【路径冲突，要上传的文件或者目录已经存在】";
		}else if(result.responseJSON.code=='-285'){
			errorHtml = "【上传文件大小大于限制】";
		}else if(result.responseJSON.code=='-5957'){
			errorHtml = "【操作不存在的bucket】";
		}else{
			errorHtml = "【上传失败，请稍后重试】";
		}
		$("#result").val(errorHtml + "\n腾讯云存储返回信息：\n" + result.responseText + "\n 详细错误信息请查看：https://www.qcloud.com/document/product/436/8432");
	};

	var progressCallBack = function (curr) {
		console.log('请稍等，文件正在上传中.... ' + parseInt(curr*100) + '%');
		$("#result").val('文件上传中...' + parseInt(curr*100) + '%');
		document.getElementById("mloading-text").innerHTML = '请稍等，文件正在上传中....' + parseInt(curr*100) + '%';
	};

	//分片上传文件,当选择大于20M大小的文件的时候用分片上传
	$('#sliceUploadFile').on('click', function () {
		$('#file').off('change').on('change', function (e) {
			var file = e.target.files[0];
			var file_size = parseInt((file.size/1024)/1024);
			var max_img_size = {php echo $config['upload_max']};
			if (file_size > max_img_size) {
				alert("当前系统上传文件不能超过" + max_img_size + "MB");
				return false;
			}


			$(".mloading-bar").show();
			$("#overlay").fadeTo(200, 0.2);
			cos.uploadFile(successCallBack, errorCallBack, progressCallBack, bucket, myFolder + file.name, file, 0);
			return false;
		});

		setTimeout(function () {
			$('#file').click();
		}, 0);

		return false;
	});
});
</script>
{/if}

{php include $this->template('_footer');}